package org.usmile.algorithms.huawei.acm;

import java.io.ByteArrayInputStream;
import java.nio.charset.StandardCharsets;
import java.util.*;

// https://blog.csdn.net/qq_34465338/article/details/128705108
public class _查找树中元素 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int size = Integer.parseInt(in.nextLine());
        int[][] nodes = new int[size][];
        for (int i = 0; i < size; i++) {
            nodes[i] = parseOneLine(in.nextLine());
        }
        int[] xy = parseOneLine(in.nextLine());
        String result = doQuery(nodes, xy[0], xy[1]);
        System.out.println(result);
    }


    private static int[] parseOneLine(String text) {
        ByteArrayInputStream stream = new ByteArrayInputStream(text.getBytes(StandardCharsets.UTF_8));
        Scanner in = new Scanner(stream);
        List<Integer> list = new ArrayList<>();
        while (in.hasNext()) {
            list.add(in.nextInt());
        }
        return list.stream().mapToInt(it -> it).toArray();
    }


    private static String doQuery(int[][] nodes, int x, int y) {
        if (x < 0 || y < 0) {
            return "{}";
        }
        Queue<Integer> queue = new LinkedList<>();
        queue.offer(0);
        int level = 0;
        List<Integer> result = new ArrayList<>();
        while (!queue.isEmpty()) {
            int size = queue.size();
            for (int i = 0; i < size; i++) {
                int index = queue.poll();
                int[] node = nodes[index];
                int currValue = node[0];
                if (level == x) {
                    result.add(currValue);
                }
                if (node.length > 1) {
                    for (int j = 1; j < node.length; j++) {
                        queue.offer(node[j]);
                    }
                }
            }
            if (level == x) {
                break;
            }
            level++;
        }

        if (y > result.size()) {
            return "{}";
        } else {
            return "{" + result.get(y) + "}";
        }
    }
}
